Is this a valid HTTP response? [migrated]

Posted by fatmck on Programmers See other posts from Programmers or by fatmck
Published on 2011-11-25T09:05:33Z Indexed on 2011/11/25 10:05 UTC
Read the original article Hit count: 202

Filed under:

I am writing a web server using C++, which responds the following for all requests:

static std::string rsp[] = { 
    "HTTP/1.1 200 OK\r\n",
    "Server: WebServer\r\n",
    "Content-Type: text/html\r\n",
    "Content-Length: 3\r\n",
    "Connection: close\r\n",
    "\r\n",
    "123"
};

the content "123" can be successfully shown in browser. But when I use apache-ab to do a test, ab always show errors like this:

ab -n 1 -c 1 http://127.0.0.1:1080/
apr_socket_recv: Connection reset by peer (104)

I thought that I'm closing the socket too quickly, so I commented the close() function. But ab just hold, ab seems to be waiting for a complete response.

© Programmers or respective owner

Related posts about http-response